<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Search extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->lang->load('breadcrumb', 'estonian');
        $this->load->model('Search_model', 'SearchModel');
        $this->load->model('Athlete_model', 'AthleteModel');
    }

    public function index() {

        $fname = $this->input->post('fname');
        $lname = $this->input->post('lname');

        if (empty($fname)) {
            redirect("search/athlete/null/" . $lname);
        } else if (empty($lname)) {
            redirect("search/athlete/" . $fname);
        } else {
            redirect("search/athlete/" . $fname . "/" . $lname);
        }
    }

    public function athlete($fname = null, $lname = null) {

        if ($fname === 'null') $fname = null;

        $data['athletes'] = $this->AthleteModel->search($fname, $lname, true);
        $this->load->template('athletes', $data);
    }

}